<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;

use Config;

class AdminController extends Controller {

    protected $_response;

    public function __construct()
    {
        $this->_response                            = array();
        $this->_response['_active']                 = array();
        $this->_response['_active']['_model']       = '';
        $this->_response['_active']['_action']      = '';
    }

    public function mapMark($arr){
        $default = array(
            "_id"            => null,
            "store_id"       => null,
            "_name"          => null,
            "_location"      => null,
            "_address"       => null,
        );

        $param = array(
            "key" 		=> Config::get('amap.key'),
            "tableid"	=> Config::get('amap.tableid'),
            "loctype"	=> "1",
        );

        $data = array_merge($default,$arr);
        $amapAddress = array(
            "_name"		=> $data['_name'],
            "_location" => $data['_location'],
            "_address"	=> $data['_address'],
            "store_id"	=> $data['store_id']
        );


        if(!empty($data['_id'])){
            //update
            $amapAddress['_id'] = $data['_id'];
            $url = Config::get('amap.update_url');
        }else{
            //create
            $url = Config::get('amap.url');
        }
        $param['data'] = json_encode($amapAddress);

        $amap = json_decode(curlPost($url , $param));

        if(!empty($amap) && $amap->status == '1'){

            $sign['is_sign'] = 1;
            $sign['amap_id'] = isset($amap->_id) ? $amap->_id : $data['_id'] ;

            return $sign['amap_id'];
        }else{
            return false;
        }

    }


}